package com.hpin.fansea.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hpin.fansea.R;
import com.hpin.fansea.bean.Community;

import java.util.List;

/**
 * Created by Aaron on 15/9/8.
 */
public class CommunityListAdapter extends BaseAdapter {

    private Context context;
    private List<Community> communityList;

    public CommunityListAdapter(Context context, List<Community> communityList) {
        this.context = context;
        this.communityList = communityList;
    }

    public void setDate(List<Community> communityList){
        this.communityList = communityList;
    }

    @Override
    public int getCount() {
        return communityList.size();
    }

    @Override
    public Object getItem(int position) {
        return communityList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder=null;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_city, null);
            viewHolder = new ViewHolder();
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.item_city_name);
            convertView.setTag(viewHolder);
        }else{
            viewHolder=(ViewHolder) convertView.getTag();
        }

        viewHolder.tv_name.setText(communityList.get(position).projectName);

        return convertView;
    }

    private class ViewHolder {
        public TextView tv_name;
    }

}